/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2022并保留所有权利。
 * Copyright 2022, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * @className: SemaphoreTest
 * @description: TODO 类描述
 * @author: mac
 * @date: 2020/12/26
 **/
public class SemaphoreTest_Executors {
    public static void main(String[] args) {
        ExecutorService  executor=Executors.newFixedThreadPool(40);

        Semaphore  semaphore=new Semaphore(3);
        for (int i = 0; i < 9; i++) {
            executor.execute(()->{
                try {
                    semaphore.acquire();
                    System.out.println(Thread.currentThread().getName()+"处理数据中......");
                    Thread.sleep(3000);
                    semaphore.release();
                    System.out.println("######");
                   System.out.println(Thread.currentThread().getName()+"处理数据完毕......");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            });
        }
        executor.shutdown();

    }
}

